<?php

namespace App\Notifications;

use App\Channels\WechatChannel;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class NoticeDriver extends Notification
{
    use Queueable;

    protected $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [WechatChannel::class];
    }

    public function toWechat($notifiable) {

        $order = $this->order;
        $date = $order->date;
        $remark = "出发地：{$order->start},目的地：{$order->end},上车时间:{$date} ";


        return $message = [
            'template_id'=> config('wechat.template_id.notice_driver'),
            'content'=>'',
            'url'=>route('driver'),
            'data'=> [
                'first'=>'您有一票新派车单，请注意出车时间。',
                'keyword1'=>$date,
                'keyword2'=>$order->name.','.$order->phone,
                'keyword3'=>$order->start,
                'remark'=>$remark,
            ],
        ];

    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
